//
//  LookVideoVC.m
//  PushLookVideo_NING
//
//  Created by NHT on 2020/3/4.
//  Copyright © 2020 HYXF. All rights reserved.
//

#import "LookVideoVC.h"
#import <IJKMediaFramework/IJKMediaFramework.h>

@interface LookVideoVC ()


@property (nonatomic, strong) IJKFFMoviePlayerController *player;

@end

@implementation LookVideoVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor blackColor];
    
    self.navigationController.navigationBar.hidden = NO;
    self.navigationController.navigationBar.translucent = YES;

    // 拉流地址 rtmp://192.168.11.181:1935/hls/movie   rtmp://192.168.20.85:1935/live/main71
    NSURL *url = [NSURL URLWithString:@"rtmp://192.168.11.181:1935/hls/movie"];
#ifdef DEBUG
    [IJKFFMoviePlayerController setLogReport:NO];
    [IJKFFMoviePlayerController setLogLevel:k_IJK_LOG_DEBUG];
#else
    [IJKFFMoviePlayerController setLogReport:NO];
    [IJKFFMoviePlayerController setLogLevel:k_IJK_LOG_INFO];
#endif

    [IJKFFMoviePlayerController checkIfFFmpegVersionMatch:YES];

    IJKFFOptions *options = [IJKFFOptions optionsByDefault];
    //    [options setOptionIntValue:2 forKey:@"videotoolbox" ofCategory:kIJKFFOptionCategoryPlayer];
    //    [options setPlayerOptionIntValue:1 forKey:@"videotoolbox"];
    
    options.showHudView = YES;//控制 显示右侧网速、连接地址 tcp-info tcp-spd 等信息

    self.player = [[IJKFFMoviePlayerController alloc] initWithContentURL:url withOptions:options];
    self.player.view.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
    self.player.view.frame = self.view.bounds;
    self.player.scalingMode = IJKMPMovieScalingModeAspectFit;
    self.player.shouldAutoplay = YES;

    self.view.autoresizesSubviews = YES;
    [self.view addSubview:self.player.view];
}
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.player prepareToPlay];
    [self.player play];
}
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];

    // 界面消失，一定要记得停止播放
    [self.player pause];
    [self.player stop];
    [self.player shutdown];
}

@end
